package multithreaded;

import java.util.Random;

public class ThreadSample2 {
    class Runner implements Runnable {
        @Override
        public void run() {
            int speed = new Random().nextInt(10);
            for (int i = 0; i < 10; i++) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("第" + (i + 1) + "秒" + Thread.currentThread().getName()
                        + "已跑到" + (i * speed) + "米(" + speed + "米/秒)");
            }
        }
    }

    public void start() {
        Runner runner = new Runner();
        Thread threadA = new Thread(runner);
        Thread threadB = new Thread(runner);
        Thread threadC = new Thread(runner);

        threadA.start();
        threadB.start();
        threadC.start();

    }

    public static void main(String[] args) {
        ThreadSample2 sample2 = new ThreadSample2();
        sample2.start();
    }
}
